package com.example.multactivity

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.example.multactivity.FourthActivity
import com.example.multactivity.ui.theme.MultActivityTheme
import com.example.multactivity.SecondActivity
import com.example.multactivity.ThirdActivity
const val FIRST_MSG = "FIRST_MSG"
const val SECOND_MSG = "SECOND_MSG"
class MainActivity : ComponentActivity() {

    
    private lateinit var textView: TextView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val first = findViewById<Button>(R.id.first)
        val editText = findViewById<EditText>(R.id.editText)
        val second = findViewById<Button>(R.id.second)
        val third = findViewById<Button>(R.id.third)
        val four = findViewById<Button>(R.id.four)

        textView = findViewById(R.id.textView)

        first.setOnClickListener {
            val intent = Intent(this, SecondActivity::class.java)
            intent.putExtra(FIRST_MSG, editText.text.toString())
            startActivity(intent)
        }

        second.setOnClickListener {
            val intent = Intent(this, ThirdActivity::class.java)
            startActivityForResult(intent, 0)
        }

        third.setOnClickListener{
            val intent = Intent(this, FourthActivity::class.java)
            startActivity(intent)
        }

        four.setOnClickListener{
            val intent = Intent(this, FifthActivity::class.java)
            startActivity(intent)
        }


    }



        override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
            super.onActivityResult(requestCode, resultCode, data)
            if (requestCode == 0) {
                if (resultCode == 1) {
                    textView.text = data?.getStringExtra(SECOND_MSG)
                }
            }
        }
}

